<?php
namespace app\mall\controller;
use controller\BasicAdmin;
use service\DataService;
use service\NodeService;
use think\Db;
use think\Request;
class Printorder extends BasicAdmin{
	/**
	 * 打印数据
	 * @return [type] [description]
	 */
	public function print_material(){
		$orderid = input('id');
		$list = Db::name('store_material_order')->alias('a')->join('ys_goods_material b','a.material_id=b.id','LEFT')->join('ys_store c','a.store_id=c.id','LEFT')->where('a.order_id',$orderid)->field('a.num,a.num,a.addtime,b.name,b.unit,b.stock,b.is_zigou,c.title')->select();		//查询订单详情
		$table = '';
		$table .= "<table>
						<thead>
						<tr>
							<th>".iconv('UTF-8', 'GB2312','原料名称')."</th>
							<th>".iconv('UTF-8', 'GB2312','门店')."</th>
                    		<th>".iconv('UTF-8', 'GB2312','申请数量')."</th>
                    		<th>".iconv('UTF-8', 'GB2312','单位')."</th>
                    		<th>".iconv('UTF-8', 'GB2312','申请时间')."</th>
                   	 	</tr>
                   	 	</thead>
                   	<tbody>";
        foreach ($list as $v){
            $table .= "<tr>
                    		<td>".iconv('UTF-8', 'GB2312',$v['name'])."</td>
                    		<td>".iconv('UTF-8', 'GB2312',$v['title'])."</td>
                    		<td>".iconv('UTF-8', 'GB2312',$v['num'])."</td>
                    		<td>".iconv('UTF-8', 'GB2312',$v['unit'])."</td>";
           	$time = date('Y-m-d H:i',$v['addtime']);
           	$table .="<td>".iconv('UTF-8', 'GB2312',$time)."</td>";
        }
        $table .= "</tr></tbody></table>";
        header("Pragma: public");  
        header("Expires: 0");  
        header("Cache-Control:must-revalidate, post-check=0, pre-check=0");  
        header("Content-Type:application/force-download");  
        header("Content-Type:application/vnd.ms-execl");  
        header("Content-Type:application/octet-stream");  
        header("Content-Type:application/download");;  
        header('Content-Disposition:attachment;filename="门店原料申请明细表.xls"');  
        header("Content-Transfer-Encoding:binary"); 
        echo $table;exit();			//必须加上exit();   防止导出调试信息
	}
}
?>